package v1

import (
	"strconv"

	"gitee.com/cyanbleeze/go-image-management/internal/service"
	"gitee.com/cyanbleeze/go-image-management/pkg/app"
	"gitee.com/cyanbleeze/go-image-management/pkg/errcode"
	"github.com/gin-gonic/gin"
)

type Detail struct{}

func NewDetail() Detail {
	return Detail{}
}

func (d Detail) Get(ctx *gin.Context) {
	id, err := strconv.Atoi(ctx.Param("id"))
	res := app.NewResponse(ctx)
	if err != nil {
		res.ToErrorResponse(errcode.InvalidParams.WithDetails(err.Error()))
		return
	}
	svc := service.New(ctx)
	de, err2 := svc.GetDetail(&service.DetailRequest{ID: uint(id)})
	if err2 != nil {
		res.ToErrorResponse(errcode.ErrorGetFavoritePictureFail.WithDetails(err2.Error()))
		return
	}
	res.ToResponse(de)
}
